package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PrizeLuck;
import com.ruoyi.system.service.IPrizeLuckService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖品抽奖Controller
 * 
 * @author ruoyi
 * @date 2021-04-07
 */
@RestController
@RequestMapping("/system/prizeluck")
public class PrizeLuckController extends BaseController
{
    @Autowired
    private IPrizeLuckService prizeLuckService;

    /**
     * 查询奖品抽奖列表
     */
    @PreAuthorize("@ss.hasPermi('system:prizeluck:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrizeLuck prizeLuck)
    {
        startPage();
        List<PrizeLuck> list = prizeLuckService.selectPrizeLuckList(prizeLuck);
        return getDataTable(list);
    }

    /**
     * 导出奖品抽奖列表
     */
    @PreAuthorize("@ss.hasPermi('system:prizeluck:export')")
    @Log(title = "奖品抽奖", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrizeLuck prizeLuck)
    {
        List<PrizeLuck> list = prizeLuckService.selectPrizeLuckList(prizeLuck);
        ExcelUtil<PrizeLuck> util = new ExcelUtil<PrizeLuck>(PrizeLuck.class);
        return util.exportExcel(list, "prizeluck");
    }

    /**
     * 获取奖品抽奖详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:prizeluck:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(prizeLuckService.selectPrizeLuckById(id));
    }

    /**
     * 新增奖品抽奖
     */
    @PreAuthorize("@ss.hasPermi('system:prizeluck:add')")
    @Log(title = "奖品抽奖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrizeLuck prizeLuck)
    {
        return toAjax(prizeLuckService.insertPrizeLuck(prizeLuck));
    }

    /**
     * 修改奖品抽奖
     */
    @PreAuthorize("@ss.hasPermi('system:prizeluck:edit')")
    @Log(title = "奖品抽奖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrizeLuck prizeLuck)
    {
        return toAjax(prizeLuckService.updatePrizeLuck(prizeLuck));
    }

    /**
     * 删除奖品抽奖
     */
    @PreAuthorize("@ss.hasPermi('system:prizeluck:remove')")
    @Log(title = "奖品抽奖", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prizeLuckService.deletePrizeLuckByIds(ids));
    }
}
